package com.tengju.user.domain.model.club;

import com.tengju.user.domain.model.user.UserId;
import com.tengju.user.domain.model.user.UserIdCode;
import com.tengju.user.domain.model.user.UserInfo;
import lombok.AllArgsConstructor;
import lombok.Getter;

import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;

/**
 * @author chenhang
 * @Date 2021/1/13
 */
@Getter
@AllArgsConstructor
public class Club {

    private ClubId clubId;

    private UserIdCode founderIdCode;

    private UserId founderUserId;

    private String clubName;

    private String clubHeadImg;

    private String createBy;

    private String updateBy;

    private LocalDateTime updateTime;

    public void update(@NotNull(message = "创始人idCode不能为空") UserIdCode founderIdCode,
                       @NotNull(message = "创始人userId不能为空") UserId founderUserId,
                       @NotNull(message = "俱乐部名称不能为空") String clubName,
                       @NotNull(message = "俱乐部头像不能为空") String clubHeadImg,
                       @NotNull(message = "操作用户不能为空") String updateBy) {
        this.founderIdCode = founderIdCode;
        this.founderUserId = founderUserId;
        this.clubName = clubName;
        this.clubHeadImg = clubHeadImg;
        this.updateBy = updateBy;
    }

    public Club(@NotNull(message = "创始人idCode不能为空") UserIdCode founderIdCode,
                @NotNull(message = "创始人userId不能为空") UserId founderUserId,
                @NotNull(message = "俱乐部名称不能为空") String clubName,
                @NotNull(message = "俱乐部头像不能为空") String clubHeadImg,
                @NotNull(message = "操作用户不能为空") String createBy) {
        this.founderIdCode = founderIdCode;
        this.founderUserId = founderUserId;
        this.clubName = clubName;
        this.clubHeadImg = clubHeadImg;
        this.createBy = createBy;
        this.updateBy = createBy;
    }

    public void changeFounder(UserInfo founderUserInfo,String updateBy) {
        this.founderIdCode = founderUserInfo.getIdCode();
        this.founderUserId = founderUserInfo.getUserId();
        this.updateBy = updateBy;
    }

    public void removeFounder(String updateBy) {
        this.founderIdCode = null;
        this.founderUserId = null;
        this.updateBy = updateBy;
    }
}
